package com.example.demo01.controller;

import com.example.demo01.entity.User;
import com.example.demo01.util.DBUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@Controller
public class UserController {
    @RequestMapping("/reg")
    @ResponseBody
    public String reg(User user){
        try(Connection conn = DBUtil.getConnection();) {
            String sql = "INSERT INTO user VALUES(NULL,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, user.getUsername());
            ps.setString(2, user.getPassword());
            ps.setString(3, user.getNickname());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return "注册成功";
    }
}
